class Solution
{
public:
    vector<vector<int>> combinationSum3(int k, int n)
    {
        vector<vector<int>> result;
        auto process = [&](int mask)
        {
            if (__builtin_popcount(mask) != k)
            {
                return;
            }
            int sum = 0;
            vector<int> nums;
            for (int i = 1; i < 10; ++i)
            {
                if (mask & (1 << (i - 1)))
                {
                    sum += i;
                    nums.push_back(i);
                }
            }
            if (sum == n)
            {
                result.push_back(nums);
            }
        };

        for (int m = 0; m <= 512; ++m)
        {
            process(m);
        }

        return result;
    }
};